package cn.yuanqiao.web.controller.system;

import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.domain.BusinessActivity;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.common.utils.SecurityUtils;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.system.domain.SysOperLog;
import cn.yuanqiao.system.domain.TenantOperLog;
import cn.yuanqiao.system.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/operlog")
public class SystemOperlogController extends BaseController
{
    @Autowired
    private ISysOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('system:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOperLog operLog)
    {
        startPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
  //  @PreAuthorize("@ss.hasPermi('system:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLog operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('system:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @PreAuthorize("@ss.hasPermi('system:operlog:remove')")
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return success();
    }

    @PostMapping
    public AjaxResult add(@RequestBody SysOperLog operLog)
    {
        return toAjax(operLogService.insertOperlog(operLog));
    }

    @PostMapping("/saveBusinessBehaviorLog")
    public AjaxResult addBusinessactivity(@RequestBody BusinessActivity a001Businessactivity)
    {
        return toAjax(operLogService.insertA001Businessactivity(a001Businessactivity));
    }

    //@RequiresPermissions("manage:BUSINESSACTIVITY:list")
    @GetMapping("/listBusinessActivity/{daid}")
    public TableDataInfo list(@PathVariable("daid") Long daid)
    {
        //startPage();
        BusinessActivity a001Businessactivity = new BusinessActivity();
        a001Businessactivity.setDaId(daid);
        List<BusinessActivity> list = operLogService.selectA001BusinessactivityList(a001Businessactivity);
        return getDataTable(list);
    }

    @Log(title = "操作日志统计", businessType = BusinessType.SELECT)
    @GetMapping("/operLogTongji")
    public AjaxResult operLogTongji(SysOperLog sysOperLog)
    {
        List<Long[]>  list = operLogService.operLogTongji(sysOperLog);
        return AjaxResult.success(list);
    }
}
